/**
 * 自定义接口说明
 */
var DEBUG = true;
var API_HOST = 'https://rqcrm.youheone.com/';
if (DEBUG) {
    API_HOST = 'https://yh.cqthesis.cn/';
}
//判断变量是否存在
        const isExitsVariable = variableName => {
            try {
                if (typeof (variableName) == "undefined" || variableName == null || variableName == "") {
            return false;
        } else {
            return true;
        }
    } catch (e) {
    }
    return false;
}
//ajax 请求
function Ajax(model) {
    if (!isExitsVariable(model.method)) {
        model.method = "POST";
    }
    //拼接url
    if (model.url.indexOf("https://") == -1 && model.url.indexOf("http://") == -1) {
        model.url = API_HOST + model.url;
    }
    //get参数拼接
    if (model.method == "get" && model.data !== undefined) {
        for (let k in model.data) {
            if (model.data[k].toString() !== '') {
                model.url = model.url + "&" + k + "=" + model.data[k];
            }
        }
        model.data = '';
    }
    //返回Promise对象
    return new Promise(
        function (resolve) {
            $.ajax({
                method: model.method,
                url: model.url,
                contentType: 'application/json; charset=UTF-8',
                header: {
                    'token': "bbbb", // 默认值
                },
                dataType:'json',
                data: JSON.stringify(model.data),
                success: (resolve) => {
                    model.success(resolve);
                },
                error: () => {
                    model.error('网络请求失败');
                }
            })
        }
    )
}

